import { customRef } from "vue";

//自定义方法
export default function updateName(initMeg:string, delay = 1000) {
    // 自定义ref实现防抖
    let timeout: number;
    return customRef((track, trigger) => {
        return {
            get() {
                track();
                return initMeg;
            },

            set(v: string) {
                clearTimeout(timeout);
                timeout = setTimeout(() => {
                    initMeg = v;
                    trigger();
                }, delay)
            }

        }
    })
}